/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Merlion.MRP.entity;

import Merlion.SCM.entity.ProductEntity;
import Merlion.SCM.entity.InventoryBatchEntity;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

@Entity
@DiscriminatorValue(value = "PDD")
public class PlannedDailyDemandEntity extends PlannedDemandEntity {

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date execDate;
    private int dailyDemand;
    private int reservedQty;
    private int adjustedQty;
    private int maxQty;
    @ManyToOne
    private PlannedWeeklyDemandEntity plannedWeeklyDemand;
    @OneToOne
    private InventoryBatchEntity productBatch;
    private boolean committed;
    private boolean created;
    private boolean depleted;
    @OneToMany(mappedBy = "pdd")
    private Collection<UnplannedDailyDemandEntity> unplannedDailyDemandEntitys;
    @OneToMany(mappedBy = "plannedDailyDemandEntity")
    private List<ReservationEntity> reservationEntities;

    public PlannedDailyDemandEntity() {
        this.committed = false;
    }

    public PlannedDailyDemandEntity(ProductEntity product, Integer yearInt, Integer monthInt, Integer weekOfMonth, Integer dayOfMonth) {
        String idString = "PDD-FIN" + product.getId().toString() + "Y" + yearInt.toString() + "M" + monthInt.toString() + "W" + weekOfMonth.toString() + "D" + dayOfMonth.toString();
        this.id = idString;
        this.yearInt = yearInt;
        this.monthInt = monthInt;
        this.weekOfMonth = weekOfMonth;
        this.dayOfMonth = dayOfMonth;

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, yearInt);
        cal.set(Calendar.MONTH, monthInt - 1);
        cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);

        if (dayOfMonth.intValue() <= 0) {
            cal.set(Calendar.MONTH, monthInt);
        }

        this.execDate = cal.getTime();
        this.product = product;
        this.reservedQty = 0;
        this.committed = false;
        this.created = false;
        this.depleted = false;
    }

    public int getMaxQty() {
        return maxQty;
    }

    public void setMaxQty(int maxQty) {
        this.maxQty = maxQty;
    }

    public boolean isCommitted() {
        return committed;
    }

    public void setCommitted(boolean committed) {
        this.committed = committed;
    }

    public boolean isCreated() {
        return created;
    }

    public void setCreated(boolean created) {
        this.created = created;
    }

    public Collection<UnplannedDailyDemandEntity> getUnplannedDailyDemandEntitys() {
        return unplannedDailyDemandEntitys;
    }

    public void setUnplannedDailyDemandEntitys(Collection<UnplannedDailyDemandEntity> unplannedDailyDemandEntitys) {
        this.unplannedDailyDemandEntitys = unplannedDailyDemandEntitys;
    }

    public int getAdjustedQty() {
        return adjustedQty;
    }

    public void setAdjustedQty(int adjustedQty) {
        this.adjustedQty = adjustedQty;
    }

    public int getReservedQty() {
        return reservedQty;
    }

    public void setReservedQty(int reservedQty) {
        this.reservedQty = reservedQty;
    }

    public int getDailyDemand() {
        return dailyDemand;
    }

    public void setDailyDemand(int dailyDemand) {
        this.dailyDemand = dailyDemand;
    }

    public List<ReservationEntity> getReservationEntities() {
        return reservationEntities;
    }

    public void setReservationEntities(List<ReservationEntity> reservationEntities) {
        this.reservationEntities = reservationEntities;
    }

    public Date getExecDate() {
        return execDate;
    }

    public void setExecDate(Date execDate) {
        this.execDate = execDate;
    }

    public InventoryBatchEntity getProductBatch() {
        return productBatch;
    }

    public void setProductBatch(InventoryBatchEntity productBatch) {
        this.productBatch = productBatch;
    }

    public PlannedWeeklyDemandEntity getPlannedWeeklyDemand() {
        return plannedWeeklyDemand;
    }

    public void setPlannedWeeklyDemand(PlannedWeeklyDemandEntity plannedWeeklyDemand) {
        this.plannedWeeklyDemand = plannedWeeklyDemand;
    }

    public boolean isDepleted() {
        return depleted;
    }

    public void setDepleted(boolean depleted) {
        this.depleted = depleted;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PlannedDailyDemandEntity)) {
            return false;
        }
        PlannedDailyDemandEntity other = (PlannedDailyDemandEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.entities.PlannedDailyDemand[ id=" + id + " ]";
    }
}
